home *** CD-ROM | disk | FTP | other *** search
/ Merciful 4 / Merciful - Disc 4.iso / software / p / psychotoads.dms / psychotoads.adf / a1719 < prev    next >
Text File  |  1989-03-31  |  44KB  |  1,286 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                           17: SOUND AND MUSIC                              233
  10.                       --------------------------
  11.  
  12. The Amiga's sound system is capable of generating stereo sound effects
  13. which would have been unheard of just a few years ago. The results are
  14. impressive even through your TV speaker, but when you connect your
  15. Amiga to a Hi-Fi, the sounds can actually shake your room!
  16.  
  17.   As you would expect from AMOS, we've come a long way since the humbe
  18. BEEP command. In fact, we've provided everything you need to
  19. incorporate mind-blowing sound effects in your own games. All the AMOS
  20. sound commands are performed independently of your Basic programs. So
  21. your soundtracks can be played continuously, without affecting the
  22. quality of the game-play in the slightest.
  23.  
  24.   Samples may be created using any of the available sampling cartridges
  25. and can be replayed with a simple SAMPLAY instruction. Each sample can
  26. be output in a variety of speeds, and may be looped repeatedly. It's
  27. even possible to play a sample as a musical note.
  28.  
  29.   Music can be converted over from a separate package such as SONIX,
  30. SOUNDTRACKER or GMC. The AMOS Music system is intelligent and will
  31. automatically stop when a sound is played through the current channel,
  32. thus allowing you to effortlessly combine both samples and music in the
  33. same sound channel, without the risk of unwanted interference effects.
  34.  
  35.   Each song can incorporate up to 256 separate instruments; the only
  36. limit to the number of songs is the amount of available memory. In
  37. order to keep the memory overhead down to an absolute minimum, all
  38. tunes are built up of a number of separate patterns. Once a pattern has
  39. been created, it can be accessed anywhere in your music using just a
  40. couple of bytes. By defining just a few key patterns, you can therefore
  41. create dozens of different tues without running short of memory.
  42.  
  43.   The best thing about the AMOS music system however, is that it's
  44. expandable. The entire source code is supplied on the data disc for you
  45. to examine or change. So you won't be left out in the cold by any
  46. future developments on the Amiga's music scene.
  47.  
  48.  
  49. Simple sound effects
  50. ====================
  51. We'll start off with a run down of the built-in sound effects included
  52. in AMOS Basic. These are the AMOS equivalent to the Amiga Basic BEEP
  53. command.
  54.  
  55.  
  56.  
  57.           BOOM (generate a noise sounding like an explosion)
  58.  
  59. BOOM
  60.  
  61. Kapow! You're dead! Use BOOM to add the appropriate stereo sound effect
  62. in your games. Traditionally this type of "White Noise" as been
  63. extremely difficult on the Amiga, but AMOS uses a clever interrupt
  64. system to create a realistic explosion effect. Example:
  65.  
  66.         Boom : Print "You're DEAD!"
  67.  
  68.  
  69.  
  70.                SHOOT (create a noise like a gun firing)
  71.  
  72. SHOOT
  73.  
  74. This command generates a simple gunshot effect. Like BOOM, SHOOT does
  75. not halt your program in any way. So if you're firing several
  76. successive shots, you may wish to add a small delay using WAIT.
  77.  
  78.         Shoot : Wait 6 : Shoot : Print "You're DEAD!"
  79.  
  80.  
  81.  
  82.                        BELL (simple bell sound)                            234
  83.  
  84. BELL [f]
  85.  
  86. BELL produces a pure tone with frequency f. f sets the pitch of the
  87. note, from 1 (very deep) to 96 (very high). 
  88.  
  89.  
  90. Sound channels
  91. ==============
  92. The Amiga's hardware can effortlessly play up to four different sounds
  93. simultaneously. This allows you to add attractive harmonics to your
  94. sound effects.
  95.  
  96.   Each sound can be output through one of four VOICES numbered from
  97. 0 to 3. You can think of these voices as a separate instruments which
  98. can independently play their own sequence of notes, samples or music.
  99. All four voices are internally combined to generate the final sound you
  100. hear through your speaker system.
  101.  
  102.   The AMOS sound instructions will happily play your sounds using any
  103. arrangement of voices you like. All AMOS sound commands use a standard
  104. way of entering your voice settings. Each voice is assigned a
  105. particular bit in a VOICE parameter like so:
  106.  
  107.         Bit 0 -> Voice 0
  108.         Bit 1 -> Voice 1
  109.         Bit 2 -> Voice 2
  110.         Bit 3 -> Voice 3
  111.  
  112. To activate the required voices, set the appropriate bits to 1. Here's
  113. a list of common values to make things a little easier
  114.  
  115.         Value  Voice used  Effect
  116.         -----  ----------  ------
  117.          15     0,1,2,3    Uses all four voices
  118.           9     0,3        These voices are combined together and
  119.                            output to the left speaker.
  120.           8     3
  121.           6     2,4        Played through the RIGHT speaker.
  122.           4     2
  123.           2     1
  124.           1     0
  125.  
  126. In order to do justice to the resulting sound effects, you'll almost
  127. certainly need to connect your Amiga to a Hi-Fi system of some sort.
  128. Most TVs are just not capable of reproducing the full range of sounds
  129. which can be generated by the Amiga's amazing hardware.
  130.  
  131.  
  132.  
  133.                    VOLUME (change the sound colume)                        235
  134.  
  135. VOLUME [v,] intensity
  136.  
  137. VOLUME changes the volume of the sounds which are to be played through
  138. one or more sound channels.
  139.  
  140.   "intensity" refers to the loudness of this sound. It can normally
  141. range from 0 (silent) to 63 (maximum). As a default, the volume is set
  142. to the same intensity for all four of the available voices. THe new
  143. volume will be used for all future sound effects, including music.
  144.  
  145.   The v parameter lets you change the volume of each voice
  146. independently. v now indicates which combination of voices are to be
  147. regulated. This second option is only used by the sound effects. It has
  148. no affect on any music you're playing. The voices are selected using a
  149. bit amp in the standard format, with each bit representing state of a
  150. single sound channel. If the bit is set to 1, then the volume of this
  151. voice will be changed, otherwise it will be unaffected. Examples:
  152.  
  153.         Volume %0001,63 : Boom : Wait 100 
  154.         Volume %1110,10 : Boom : Wait 50
  155.         Play 40,0 : Wait 30
  156.         Volume 50 : Play 40,0
  157.  
  158.  
  159. Sampled sound
  160. =============
  161. If you had to generate all the sound effects you need, directly inside
  162. your computer, you would be faced with an impossible task. In practive,
  163. it's often much easier to take a real sound from an external source,
  164. such as a tape recorder, and convert it into a list of numbers which
  165. can be held in your computer's memory.
  166.  
  167.   Eacn number represents the volume of a particular sample of the
  168. sound. By rapidly playing these values back through the Amiga's sound
  169. chips, you can recreate a realistic impression of the original sound.
  170. This technique forms the basis of the sampled sound effects found in
  171. most modern computer games.
  172.  
  173.   If you want to create your own samples, you'll be forced to buy a
  174. separate piece of hardware known as a SAMPLER CARTRIDGE. Although these
  175. cartridges are fun, they're certainly not essentia. AMOS Basic is
  176. perfectly capable of playing any existing sound sample, without the
  177. need for any expensive add-ons.
  178.  
  179.   Currently there are hunderds of sound effects available from the
  180. public domain (PD), covering the vast majority of the effects you'll
  181. need in your games. We've even included a selection of useful samples
  182. on the AMOS data disc for you to experiment with.
  183.  
  184.  
  185.  
  186.                   SAM PLAY (play a sound sample from
  187.                          the AMOS sample bank)
  188.  
  189. SAM PLAY s
  190. SAM PLAY v,s
  191. SAM PLAY v,s,f          The SAMP PLAY instruction plays a sampled sound
  192.                         straight through your loudspeaker system. All
  193. samples are normally stored in memory bank number 5, but this may be       236
  194. freely changed using the SAM BANK command.
  195.  
  196.   s is the number of the sample bank which is to be played. There's no
  197. limit of the samples you can store in a bank other than the available
  198. memory. If you want to use your own samples with this instruction,
  199. you'll need to incorporate them into an AMOS memory bank. Full details
  200. can be found towards the end of this section.
  201.  
  202.   v is a bit-map containing a list of voices your sample will use. As
  203. usual, there's one bit for each possible voice. To play your samples
  204. through the required voice, simply set the relevant bit to 1.
  205.  
  206.   f holds the playback speed of your sample, measured in hertz. This
  207. specifies the number of samples which are to be played each second.
  208. Typical sample speeds range from 4000, for noises such as explosions,
  209. to 10000 for recognisable speech effects. By changing the playback
  210. rate, you can freely adjust the pitch of your sound over a large range.
  211. So a single sample can be used to generate dozens of different sounds.
  212. Example:
  213.  
  214.         Load "AMOS_DATA:Samples/Sample_Demo.abk"
  215.         For S=1 To 11
  216.           Locate 0,0 : ? "Playing sample ";S
  217.           Sam Play S
  218.           Locate 0,24 :Centre "<Hit a key to continue>" :Wait Key :Cline
  219.         Next S
  220.         Wait Key
  221.         Sam Play 1,11 : Wait 5 : Sam Play 2,11
  222.         Wait key
  223.         Sam Play 1,1,2000
  224.         Wait Key
  225.         Sam Play 1,1,15000
  226.  
  227. A further demonstration of this command can be found in EXAMPLE 17.1
  228.  
  229.  
  230.  
  231.                   SAM BANK (change the current bank)
  232.  
  233. SAM BANK n
  234.  
  235. Assigns a new memory bank to be used for your samples. All future
  236. SAM PLAY instructions will now take their sounds directly from this
  237. bank.
  238.  
  239.   It's possible to exploit this feature to hold several complete sets
  240. of samples alongide each other. You can then between these samples at
  241. any time, with just a simple call to the SAM BANK.
  242.  
  243.  
  244.  
  245.                   SAM RAW (play a sample from memory)
  246.  
  247. SAM RAW voice,address,length,frequency
  248.  
  249. Plays a raw sample stored anywhere in the Amiga's memory. "voice" is a     237
  250. bit-pattern in standard format which specifies the list of voices your
  251. sample is to use. Each bit in the pattern selects a single channel to
  252. be played (see sound channels).
  253.  
  254.   "address" holds the address of your sample. Normally, this will refer
  255. to the inside of an existing AMOS memory bank. "length" contains the
  256. length of the sample you wish to play. "frequency" indicates the sample
  257. speed to be used for the playback (in samples per second or Hz). This
  258. may be very different to the rate at which the sample was originally
  259. recorded.
  260.  
  261.   SAM RAW lets you play standard Amiga samples straight through your
  262. loudspeaker, without the need to create a special memory bank (see
  263. Creating a sample bank). It's now your responsibility to manage your
  264. samples in memory, and enter the sample parameters by hand. SAM RAW is
  265. great for browsing through files from your disc collection. Use BLOAD
  266. to hold a file in a bank and then use SAM RAW to play the data. With
  267. luck you should come across some interesting sounds. Examples:
  268.  
  269.         Reserve As Work 10,55000
  270.         Bload "Samples/Samples.abk",start(10)
  271.         Sam Raw 15,start(10,length(10),10000
  272.  
  273.  
  274.  
  275.                       SAM LOOP (repeat a sample)
  276.  
  277. SAMP LOOP ON/OFF
  278.  
  279. The SAM LOOP directive informs AMOS Basic that all subsequent samples
  280. are to be repeated continuously. Examples:
  281.  
  282.         Load "AMOS_DATA:Samples/Sampledemo.abk"
  283.         Sam Loop On
  284.         For S=1 To 11
  285.           Locate 0,0 : Print "Playing sample ";S
  286.           Sam Play S
  287.           Locate 0,24 : Centre "<Hit a key to continue>":Wait Key :Cline
  288.         Next S
  289.         Sam Loop Off
  290.  
  291. This looping effect can be deactivated with a simple call to the
  292. SAM LOOP OFF command.
  293.  
  294.  
  295. Creating a sample bank
  296. ======================
  297. If you're indenting to play your own samples using SAM PLAY, you'll
  298. first need to load them into a memory bank. This can be achieved with
  299. the SAMMAKER program supplied on the AMOS data disc.
  300.  
  301.   On start-up, SAMMAKER presents you with a standard AMOS file
  302. selector. Enter the filename of the first sample to be stored in your
  303. new bank, and press RETURN. If AMOS can't find the sampling rate,
  304. you'll be asked to enter it directly. It doesn't really matter if you
  305. make a mistake at this point, as you can safely replay your samples at
  306. any speed you like.
  307.  
  308.   After a short delay, you'll be prompted for the next sample to be
  309. installed into the bank. When you've reached the end of your samples,
  310. type SAVE at the file selector to save your samples onto the disc.
  311. You'll be automatically prompted for the destination filename of your
  312. new bank. This can now be entered into AMOS Basic using the LOAD
  313. command like so:
  314.  
  315.         Load "Sample.abk"
  316.         Load "Sample.abk",6 : Rem Loads sample into bank #6.               238
  317.  
  318.  
  319.  
  320. Music
  321. =====
  322. The AMOS music system allows you to easily add an attractive backing
  323. track to your games. Music can be created from a variety of sources,
  324. including GMC, SOUNTRACKER or SONIX.
  325.  
  326.   In order to convert these musics into the special AMOS format, you'll
  327. need to use one of the translation programs included on the AMOS data
  328. disc. GMC music should have been saved using the SAVE DATA icon, as
  329. this copies both the music and the instrument definitions into a single
  330. large data file.
  331.  
  332.  
  333.  
  334.                      MUSIC (play a piece of music)
  335.  
  336. MUSIC n
  337.  
  338. The AMOS MUSIC command starts a piece of music from the music bank
  339. (#3). This music will be played independently of your Basic program,
  340. without affecting it in the slightest.
  341.  
  342.   Normally, it's possible to store several complete arrangements in the
  343. same bank. Each composition is assigned its own individual music
  344. number. The only exception to this rule is music created by GMC, which
  345. only allows you to place one song in the bank at a time. Example:
  346.  
  347.         Load "MUSIC/Musicdemo.abk"
  348.         Music 1
  349.  
  350. The AMOS music system is intelligent, and will automatically suspend
  351. your music for the duration of any subsequent sound effects on the
  352. current channel. When the sound has finished, your tune will be
  353. restarted from its previous position. Up to three separate tunes can be
  354. started at a time. Each new music command stops the current song, and
  355. pushes its status onto a stack. Once the song has concluded, the old
  356. music will commence from where it left off.
  357.  
  358.  
  359.  
  360.               MUSIC STOP (stop a single section of music)
  361.  
  362. MUSIC STOP
  363.  
  364. Halts the current piece of music. If another music is active, it will
  365. be restarted immediately.
  366.  
  367.  
  368.  
  369.                     MUSIC OFF (turn off all music)
  370.  
  371. MUSIC OFF
  372.  
  373. THe MUSIC OFF command deactivates your music completely. In order to
  374. restart it, you'll need to execute your original series of MUSIC
  375. instructions again from scratch.
  376.  
  377.  
  378.  
  379.              TEMPO (change the speed of a sample of music)                 239
  380.  
  381. TEMPO s
  382.  
  383. TEMP modifies the speed of any tune which is currently being played
  384. with the MUSIC command. s is the new speed, and can range from 1 (very
  385. slow) to 100 (very fast). Not all instruments are capable of playing at
  386. this maximum speed, however. The practical limit is closer to 50. For a
  387. demonstration, place the AMOS data disc into the current drive and
  388. type:
  389.  
  390.         Load "AMOS_DATA:Music/Musicdemo.abk"
  391.         Music 1
  392.         Tempo 35
  393.         Tempo 5
  394.  
  395. Note that music created with GMC often contains labels which set the
  396. tempo directly inside the arrangement. These labels will override the
  397. tempo settings within AMOS Basic. So it's not advisable to use them in
  398. your own music.
  399.  
  400.  
  401.  
  402.              MVOLUME (set the volume of a piece of music)
  403.  
  404. MVOLUME n
  405.  
  406. Changes the volume of the entire piece of music to intensity n (0-63).
  407.  
  408.  
  409.  
  410.                   VOICE (activate one or more voices
  411.                          of a piece of music)
  412. VOICE mask
  413.  
  414. Activates one or more voices of the music independently. Usually each
  415. voice will contain its own separate melody which will combined through
  416. your speakers to generate the eventual music.
  417.  
  418.   "mask" is a bit mask in the normal AMOS format which specifies which
  419. voices you wish to play. Each bit represents the state of one voice in
  420. the music. If it's set to 1, the voice will be played, otherwise it
  421. will be totally unused.
  422.  
  423.         Load "AMOS_DATA:Music/Musicdemo.abk"
  424.         Music 1
  425.         For V=0 To 15
  426.         Locate 0,0 : Print "Voice ";V
  427.         Voice V
  428.         Wait 100
  429.         Next V
  430.         Direct
  431.         Voice %0001 : Rem Activate voice 0                                 240
  432.         Voice %0010 : Rem                1
  433.         Voice %1001 : Rem                3 and 0
  434.         Voice %1111 : Rem                4
  435.  
  436.  
  437.  
  438.                         =VUMETER (volume meter)
  439.  
  440. s=VUMETER(v)
  441.  
  442. The VUMETER function tests voice v and returns the volume of the
  443. current note which is being played by your music. s is an intensity
  444. value between 0 and 63. v is the number of a single voice to be checked
  445. (0-3).
  446.  
  447.   Using this function, you can make your sprites dance to a piece of
  448. music! Load EXAMPLE 17.2 for a demonstration.
  449.  
  450.   Note there's also an AMAL version of this intruction which allows you
  451. to create realtime VU meters using interrupts. See the section on the
  452. VU command for more information.
  453.  
  454.  
  455. Playing a note
  456. ==============
  457.  
  458.  
  459.                           PLAY (play a note)
  460.  
  461. PLAY [voice,] pitch,delay
  462.  
  463. Plays a single note through the loudspeaker of your TV or Hi-Fi.
  464. "pitch" sets the tone of this sound, ranging from 0 (low) to 96 (high).
  465. Rather than just being an arbitrary number, each pitch is associated
  466. with one of the notes (A,B,C,D,E,F,G). This can be seen from the
  467. following table.
  468.  
  469.                            Octave
  470.               --------------------------------
  471.                0   1   2   3   4   5   6   7
  472.         Note                Pitch
  473.         ----  --------------------------------
  474.         C     1   13  25  37  49  61  73  85
  475.         C#    2   14  26  38  50  62  74  86
  476.         D     3   15  27  39  51  63  75  87
  477.         D#    4   16  28  40  52  64  76  88
  478.         E     5   17  29  41  53  65  77  89
  479.         F     6   18  30  42  54  66  78  90
  480.         F#    7   19  31  43  55  67  79  91
  481.         G     8   20  32  44  56  68  80  92
  482.         G#    9   21  33  45  57  69  81  93
  483.         A     10  22  34  46  58  70  82  94
  484.         A#    11  23  35  47  59  71  83  95
  485.         B     12  24  36  48  60  72  84  96
  486.  
  487. It should be apparent that the notes go up in a cycle of 12. This cycle    241
  488. is known as an octave.
  489.  
  490.   The optional voice parameter allows you to play your notes through
  491. any combination of the Amiga's four voices. As usutal it's a bit-map in
  492. the format:
  493.  
  494.         Bit  Voice
  495.         ---  -----
  496.          0     0              Setting a bit to a value of 1 plays the
  497.          1     1              relevant voice. "delay" sets the length
  498.          2     2              of the pause between the play command and
  499.          3     3              the next Basic instruction. This allows
  500.                               you to play each note before preceding
  501.                               the next one.
  502.  
  503. A delay of zero starts a note and immediately jumps to the next Basic
  504. instruction. By playing several notes after another, you can easily
  505. generate some attractive harmonic effects. Examples:
  506.  
  507.         Play 1,40,0 : Play 2,50,0
  508.         Wait Key
  509.         Play 1,40,15 : Play 2,50,15
  510.         Do
  511.           T=Rnd(96) : V=Rnd(15) : Play V,T,3
  512.         Loop
  513.  
  514. PLAY is not limited to pure notes incidentally. It's also possible to
  515. assign complex waveforms to the sound generator using the powerful WAVE
  516. and NOISE commands.
  517.  
  518.  
  519. Waveforms and envelopes
  520. =======================
  521.  
  522.  
  523.                      SET WAVE (define a waveform)
  524.  
  525. SET WAVE wave,shape$
  526.  
  527. The SET WAVE instruction provides you with the ability to define your
  528. very own instruments for use with the AMOS Basic PLAY instruction. The
  529. sound of yur instrument depends on the shape of a waveform held in the
  530. Amiga's memory. This forms a template which is repeated to produce your
  531. final note.
  532.  
  533.   "wave" is the number of the waveform you wish to define. Allowable
  534. wave numbers start from 2 onwards. That's because waves zero and 1 are
  535. already installed. Wave zero holds a random noise pattern for producing
  536. explosion effects. Wave one is a smooth sine wave and generates the
  537. pure tones used by the standard PLAY instruction.
  538.  
  539.   The shapes of your waveform are set using a list of 256 numbers which
  540. are entered using the SHAPE$ parameter. Now look at the uppest diagram
  541. in the AMOS4.PIC (file included with this manual packet).
  542.  
  543.          < picture AMOS4.PIC, the uppest diagram >                         242
  544.  
  545.   Each number represents the intensity of an individual section of the
  546. waveform. This is equivalent to the height of just one point in the
  547. diagram. Possible values for intensity range from -128 to 127. Since
  548. AMOS strings are only capable of holding *positive* numbers (0-255),
  549. you'll need to convert your negative values into a special internal
  550. format before use. The required value can be calculated by simply
  551. adding 256 to the negative numbers in your list.
  552.  
  553.   Here's a program which demonstrates how the triangular wave in the
  554. previous diagram could be created in AMOS Basic
  555.  
  556.         S$=""
  557.         For I=-128 To 127
  558.           X=I : If X<0 Then Add X,256
  559.           S$=S$+Chr$(X)
  560.         Next I
  561.         Set Wave 2,S$
  562.  
  563. Before playing your waveform you have to tell AMOS Basic which channels
  564. are to be assigned to your wave. This can be achieved using the WAVE
  565. command. Add the following line to the previous routine
  566.  
  567.         Wave 2 To 15 : For S=10 To 60 : Play S,10 : Next S
  568.  
  569. The Best way to reproduce the effect of a real instrument is to combine
  570. several SINE waves together. An example of one of these sine waves can
  571. be seen in the picture AMOS4.PIC:
  572.  
  573.          < picture AMOS4.PIC, the diagram in the middle >                  243
  574.  
  575. Adding several of these waves together, with different sizes and
  576. separate starting points, produces waves in the following pattern:
  577.  
  578.          < picture AMOS4.PIC, the lowest diagram >
  579.  
  580. This generates the smooth harmonics needed for your notes. Here's an
  581. example:
  582.  
  583.         SHAPE$="" : Degree
  584.         For S=0 To 255
  585.           V=Int((Sin(S)/2+SIN(S*2+45)/4)*128)+127
  586.           SHAPE$=SHAPE$+Chr$(V)
  587.         Next S
  588.         Set Wave 2,SHAPE$ : Wave 2 to 15
  589.         For N=10 to 60 : Play N,10 : Next N
  590.  
  591.  
  592.  
  593.           WAVE (assign a wave to one or more sound channels)
  594.  
  595. WAVE w To v
  596.  
  597. WAVE assigns wave number w to one or more sound channels. v contains a
  598. bit-map in the standard format. If a bit in the pattern is set to 1
  599. then the approrpriate voices are used by PLAY, otherwise they will be      244
  600. completely unaffected.
  601.  
  602.   As a default, wave zero is reserved for the NOISE channel, and wave
  603. one contains a sine wave. Here are some examples:
  604.  
  605.         Wave 0 To %0001 
  606.         Play 1,40,0
  607.         Wave 0 To %1100
  608.         Play 20,10
  609.         Wave 1 To %1111
  610.         Play 60,0
  611.  
  612.  
  613.                NOISE (assign a noise wave to a channel)
  614.  
  615. NOISE TO voices
  616.  
  617. Applies a white noise effect (wave 0) to the selected voices. Load
  618. EXAMPLE 17.3 for a demonstration.
  619.  
  620.   "voices" is a standard bit pattern. The first four bits represent the
  621. four possible voices, starting from zero. NOISE is equivalent to the
  622. command:
  623.  
  624.         Wave 0 To voices
  625.  
  626. Examples:
  627.  
  628.         Noise To 15
  629.         Play 60,0
  630.         Play 30,0
  631.  
  632.  
  633.  
  634.                        DEL WAVE (delete a wave)
  635.  
  636. DEL WAVE n
  637.  
  638. Deletes a wave which has previously been defined using SET WAVE. n is
  639. the number of the wave, and starts at 2. It's impossible to delete the
  640. built-in NOISE ans SINE waves using this instruction. After the wave
  641. has been erased, all voices will be reset to the standard SINE wave
  642. (default).
  643.  
  644.  
  645.  
  646.                   SAMPLE (assign a sample to a wave)
  647.  
  648. SAMPLE n TO voices
  649.  
  650. This is the most powerful cersion of all the wave commands. It assigns
  651. a sample stored in the sample bank to the current wave. Play will now
  652. take an instrument straight from the sample bank.
  653.  
  654.         Load "Samples/sample1.abk"                                         245
  655.         Sample 1 To 15
  656.         For I=20 To 50
  657.           Play I,50
  658.         Next I
  659.  
  660. As usual "voices" allows you to select a range of voices to be set by
  661. the instruction. It's a standard bit-map; Bit 0 -> Voice 0   etc...
  662.  
  663.   Note!: The range of notes that a sample can be played with, depends
  664. on its original recording rate. If a note is too high, AMOS may not be
  665. able to play it at all. The acceptable range varies from a sample to
  666. sample, but it's usually between 10 and 50.
  667.  
  668.  
  669.  
  670.                  SET ENVEL (create a volume envelope)
  671.  
  672. SET ENVEL wave,phase TO duration,volume
  673.  
  674. The SET ENVEL command smoothly changes the volume of a note while it's
  675. being played. In the real world, sounds don't just sprint into
  676. existence fully formed. They tend to evolve over a period of time,
  677. according to a pattern known as the volume envelope. The shape of this
  678. envelope varies depending on the type of instrument you are playing. A
  679. typical example of one of these envelopes is shown in the picture
  680. AMOS5.PIC.
  681.  
  682.          < picture AMOS5.PIC >
  683.  
  684. The sound is split up into four phases: Attack decay, sustain and
  685. release. AMOS Basic allows you to define your envelopes using up to        246
  686. seven separate steps. Each step represents a steady change in the
  687. volume of the current note.
  688.  
  689.   "wave" is a number of the waveform which will be affected by this
  690. instruction. It's possible to use any waveform you like for this
  691. purpose, including the built-in NOISE and SINE generators.
  692.  
  693.   "phase" holds the number of the particular phase which is to be
  694. defined, ranging from 0 to 6.
  695.  
  696.   "duration" specifies the length of the current step in units of a
  697. 50th of a second. This determines the apparent speed of the volume
  698. change to be generated in this phase.
  699.  
  700.   "volume" specifies the volume which is to be reached by the end of
  701. this phase. Allowable volume levels range from 0-63.
  702.  
  703.   It's important to understand that this volume is relative to the
  704. intensity you've previously st with the VOLUME command. So even if the
  705. note is quiet, the shape of the envelope will be perfectly reserved.
  706. Now for some examples:
  707.  
  708.         Set Envel 1,0 To 200,63 : Rem Sets the 1st step.
  709.         Play 40,0
  710.  
  711. As you can hear, the volume of your sound starts from zero, and
  712. increases to a maximum intensity during the length of the note. Now
  713. let's try defining something a little more complicated.
  714.  
  715.         Set Envel 1,0 To 15,60
  716.         Play 40,0 : Wait Key
  717.         Set Envel 1,1 To 1,50
  718.         Play 40,0 : Wait Key
  719.         Set Envel 1,2 To 10,50
  720.         Play 40,0 : Wait Key
  721.         Set Envel 1,3 To 50,0
  722.         Play 40,0
  723.  
  724. Finally, here's an example of a NOISE envelope:
  725.  
  726.         Noise To 15
  727.         Set envel 0,0 To 1000,30
  728.         Play 40,0
  729.         Wait Key
  730.         Music Off
  731.  
  732. Don't confuse waves and envelopes. A wave sets the frequency components
  733. of your notes, whereas an envelope simply changes their volume
  734. according to a set pattern.
  735.  
  736.  
  737. Speech
  738. ======
  739. Your Amiga is supplied with a powerful speech synthesizer program which
  740. can be found on the standard Workbench disc. With the help of this
  741. routine, your AMOS programs can be made to speak. Speech is especially
  742. userful in education, as many yound people will respond far better to
  743. the spoken word than to boring text.
  744.  
  745.   One word of caution though. Since the narrator package is independent
  746. of AMOS Basic, we can't attest to its absolute reliability. You're
  747. unlikely to encounter any serious problems, but it's well worth
  748. treating it with a littlle care.
  749.  
  750.  
  751.  
  752.                          SAY (speak a phrase)                              247
  753.  
  754. SAY t$[,mode]
  755.  
  756. The SAY command is incredibly easy to use. Enter your text in normal
  757. English, concluding your phrase with a punctuation mark such as full
  758. stop. SAY will now translate your words into an internal format and
  759. speak them directly through your loudspeaker. Example:
  760.  
  761.         Say "AMOS Basic can really speak"
  762.  
  763. The first time you use this instruction, the narrator.device will
  764. automatically be loaded from disc. So it's vital to ensure that an
  765. appropriate disc is placed in the current drive before using this
  766. system, as otherwise you may get an Intuition style requester box.
  767.  
  768.   "mode" toggeles between two separate speech modes. As a default, your
  769. program will wait for the duration of the speech, and any music or
  770. sound effects will be temporarily suspended. Setting "mode" to a value
  771. of one activates multitasking system which allows you to output your
  772. speech whilst AMOS is executing your program. Inevitably, this will
  773. slow down your basic routines Considerably. To return your speech back
  774. to normal, set mode to zero.
  775.  
  776.   If the narrator system cannot understand what you are attempting to
  777. speak you won't get an error messagel, but the command will be
  778. automatically aborted. Also note that the narrator can occasionally get
  779. slightly confused with very short sentences. Sometimes the remainder of
  780. the previous phrase is tagged to the end of the current voice. The
  781. problem can be solved by simply adding a list of spaces to the end of
  782. your text. These will wipe out the unwanted speech data.
  783.  
  784.  
  785.  
  786.                      SET TALK (set speech effects)
  787.  
  788. SET TALK sex,mode,pitch,rate
  789.  
  790. This allows you to change the type of voice which will be used by the
  791. SAY command. "sex" chooses between a male (0) or female (1). In all
  792. honesty, it's not a particularly realistic rendition. Better effects
  793. can be created by simply increasing the frequency of the voice using
  794. the pitch parameter.
  795.  
  796.   "mode" adds a strange rhythmic pattern to the voice. This can be
  797. activated by setting "mode" to a value of 1.
  798.  
  799.   "pitch" changes the frequency of the voice, from 65 to 320.
  800.  
  801.   "rate" specifies the speed, measured in the words per minute (40-400).   248
  802.  
  803.   Any of the above parameters can be omitted if required. Providing you
  804. keep the commas in their normal positions, you can change any set of
  805. options independently.
  806.  
  807.  
  808.  
  809. Filter effects
  810. ==============
  811.  
  812.  
  813.                    LED (activate a high pass filter/
  814.                            change power led)
  815.  
  816. LED ON/OFF
  817.  
  818. The LED command has two completely separate actions. Not only does it
  819. toggle the POWER led on your Amiga's console (in KickStart versions 
  820. 1.3 just makes the led a little darker), but it also controls a special
  821. high pass filter.
  822.  
  823.   The filter changes the way high frequency sounds are treated by the
  824. system. Normally, these sounds are filtered out so as to avoid the risk
  825. of unwanted distorion effects. Unfortunately, this robs many percussion
  826. instruments of their timbre. By turning off the filter, you can
  827. recapture the essential quality of many instruments.
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.                            18: THE KEYBOARD                                249
  837.                       --------------------------
  838.  
  839. AMOS Basic provides you with dozens of useful keyboard commands. These
  840. can be used in anything from an Arcade game to an Adventure. It's even
  841. possible to write a fully fledged wordprocessor entirely in AMOS Basic!
  842.  
  843.  
  844.  
  845.                  =INKEY$ (function to get a keypress)
  846.  
  847. k$=INKEY$
  848.  
  849. This function checks whether the user has pressed a key, and returns
  850. its value in the string k$
  851.  
  852.   Note the INKEY$ command doesn't wait your input in any way. If the
  853. user hasn't entered a character, INKEY$ will simply return an empty
  854. string "".
  855.  
  856.   INKEY$ is only capable of reading keys which return a specific Ascii
  857. character from the keyboard. Ascii is a standard code used to represent
  858. all the characters which can be printed on the screen.
  859.  
  860.   It's important to realise that some keys, like HELP button or the
  861. function keys, use a rather different format. If INKEY$ detects such a
  862. key, it will return a character with a value of zero (CHR$(0)). You can
  863. now find the internal scan code of this key using a separate SCAN CODE
  864. function.
  865.  
  866.  
  867.  
  868.                =SCANCODE (input the scancode of the last
  869.                         key input with INKEY$)
  870.  
  871. s=SCANCODE
  872.  
  873. SCANCODE returns the internal scancode of a key which has previously
  874. entered using the INKEY$ function. This allows you to check for keys
  875. which do not produce a character from the keyboard, such as HELP or
  876. TAB. Type the following small example:
  877.  
  878.       Do
  879.         While K$=""
  880.           K$=Inkey$
  881.         Wend
  882.         If Asc(K$)=0 Then Print "You pressed a key with no ASCII Code"        
  883.         Print "The Scancode Is";Scancode
  884.         K$=""
  885.       Loop
  886.  
  887.  
  888.                 =KEY STATE (test whether an individual                     250
  889.                          key has been pressed)
  890.  
  891. t=KEY STATE(s)
  892.  
  893. Check if a specific button has been pressed on the Amiga's keyboard. s
  894. is the internal scancode of the key you want to check. If this key is
  895. currently being depressed then KEY state will return a value of true
  896. (-1), otherwise the result will be false (0).
  897.  
  898.  
  899.  
  900.                    =KEY SHIFT (return the status of
  901.                             the shift keys)
  902.  
  903. keys=KEY SHIFT
  904.  
  905. KEY SHIFT returns the current status of the various control keys. These
  906. keys such as SHIFT or Alt cannot be detected using the standard INKY$
  907. or SCANCODE system. But you can easily test for any combination of
  908. control keys with just a single call to the KEY SHIFT function. "keys"
  909. is a bit map in the following format:
  910.  
  911.         Bit  Key Tested         Notes
  912.         ---  ----------         -----
  913.          0   Left SHIFT
  914.          1   Right SHIFT 
  915.          2   Caps Lock          Either ON or OFF
  916.          3   CTRL
  917.          4   Left ALT
  918.          5   Right ALT
  919.          6   Left AMIGA         C= key on some keyboards
  920.          7   Right AMIGA
  921.  
  922. If a bit is set to a one, then the associated button has been held down
  923. by the user.
  924.  
  925.  
  926.  
  927.                     INPUT$(n) (function to input n
  928.                        characters into a string)
  929.  
  930. INPUT$ enters n characters straight from the keyboard, waiting for each
  931. one in turn. As with INKEY$, these characters are not echoed onto the
  932. screen.
  933.  
  934.   x$ is a string variable which will be loaded with your new
  935. characters. n holds the number of characters to be entered. Example:
  936.  
  937.         Clear Key : Print "Type In Then Characters"
  938.         C$=INPUT$(10) : Print "You entered ";C$
  939.  
  940. This insturction *not* the same as the standard INPUT command. The two
  941. instuctions are completely different. Also note that there's a special
  942. version of INPUT$ which can be used to read your characters from the
  943. disc.
  944.  
  945.  
  946.  
  947.                      WAIT KEY(wait for a keypress)                         251
  948.  
  949. WAIT KEY 
  950.  
  951. Waits for a single keypress.
  952.  
  953.  
  954.  
  955.                   KEY SPEED (change key repeat speed)
  956.  
  957. KEY SPEED lag,speed
  958.  
  959. KEY SPEED lets you tailor the speed of the keyboard to your own
  960. particular taste. The new speed will be used for every part of the AMOS
  961. system, including the editor. 
  962.  
  963.   "lag" is the time in 50th of a second between pressing a key, and the
  964. start of the repeat sequence.
  965.  
  966.   "speed" is the delay of second between each successive character.
  967.  
  968.  
  969.  
  970.                 CLEAR KEY (initialise keyboard buffer)
  971.  
  972. CLEAR KEY
  973.  
  974. Whwnever you enter a character from the keyboard, its Ascii code is
  975. placed in an area of memory known as the keyboard buffer. It is this
  976. buffer that is sampled by the INKEY$ function to get your key presses.
  977.  
  978.   CLEAR key erases this buffer completely, and returns your keyboard to
  979. this original state. It's especially helpful at the start of a program,
  980. as the buffer may well be full of unwanted information. You can also
  981. call it immediately before a WAIT KEY comand to ensure that the program
  982. waits for a fresh keypress before preceding.
  983.  
  984.  
  985.  
  986.             PUT KEY (Put a string into the keyboard buffer)                252
  987.  
  988. PUT KEY a$
  989.  
  990. Loads a string a characters directly into the keyboard buffer. Carriage
  991. returns can be included using a CHR$(13) character.
  992.  
  993.   The most common use of PUT KEY is to set up defaults for your input
  994. routines. Here's a demonstration:
  995.  
  996.         Do
  997.           Put Key "No"
  998.           Input "Another Game";A$
  999.           If A$="No" Then Exit
  1000.         Loop
  1001.  
  1002.  
  1003.  
  1004. Input/Output
  1005. ============
  1006.  
  1007.                  INPUT (load a value from the user and
  1008.                           put it a variable)
  1009.  
  1010. INPUT 
  1011.  
  1012. Provides you with a standard way of entering information into one or
  1013. more variables. There are two possible formats for this instrucion:
  1014.  
  1015. INPUT vars[;]
  1016.  
  1017. Enters a list of variables directly from the keyboard. "var" can
  1018. contain any set of variables you like, separated by commas. A question
  1019. mark will be automatically displayed at the current cursor position.
  1020.  
  1021. INPUT "Prompt";variable list[;]
  1022.  
  1023. Prints out the "prompt" string before entering your information. Note
  1024. that you must always place a semi-colon between your text and the
  1025. variable list. You are *not* allowed to use a comma for this purpose.
  1026.  
  1027.   The optional semi-colon ";" at the end of your variable list
  1028. specifies that the text cursor will not be affected by the INPUT
  1029. instruction, and will retain its original position after the data has
  1030. been entered.
  1031.  
  1032.   When you execute one of these commands, Basic will wait for you enter
  1033. the required information from the keyboard. Each variable in your list
  1034. must be matched by a single value from the user. These values must be
  1035. of the same as your original values, and should be separated by commas.
  1036.  
  1037.  
  1038.  
  1039.                       LINE INPUT (input a list of                          253
  1040.                    variables separated by a Return)
  1041.  
  1042. LINE INPUT "Prompt";variable list[;]
  1043.  
  1044. Line input is exactly same as INPUT, except that it uses a Return
  1045. instead of a comma to separate each value you enter from the keyboard.
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.                           19: OTHER COMMANDS                               254
  1053.                      ----------------------------
  1054.  
  1055.  
  1056.                                PRINT / ?
  1057.                (print a list of variables to the screen)
  1058.  
  1059. PRINT items
  1060.  
  1061. The PRINT instruction displays some information on the screen, starting
  1062. from the current cursor position. 
  1063.  
  1064.   Each element in your list must be separated by either semi-colon or a
  1065. comma. A semi-colon prints the data immediately after the previous
  1066. value, whereas a comma first moves the cursor to the next TAB position
  1067. on the screen.
  1068.  
  1069.   Normally the cursor will be advanced downwards by a single line after
  1070. each PRINT instruction. This can be suppressed by adding a separator
  1071. after the print.
  1072.  
  1073.         PRINT 10,20*10,"Hel";
  1074.         PRINT "lo"
  1075.  
  1076.  
  1077.  
  1078.                        USING (formatted output)
  1079.  
  1080. PRINT USING format$;variable list
  1081.  
  1082. The USING statement is used in conjunction with PRINT to provied fine
  1083. control over the format of your printed output.
  1084.  
  1085.   format$ specifies a list of characters which defines the way your
  1086. variables will be displayed on the screen. Any normal text in this
  1087. string will be printed directly, but if you include one of the
  1088. characters ~#+-.;^ then one of a range of useful formatting operations
  1089. will be performed. 
  1090.  
  1091.  ~  Formats a sting variable. Every ~ is replaced by a single character
  1092.     from your output string, taken from left to right.
  1093.  
  1094.         PRINT USING "This is a ~~~~~ demonstration of USING";"Small"
  1095.  
  1096.  #  Each hash character specifies a single digit to be printed out from
  1097.     your cariable. Any unused digits in this list will be automatically    255
  1098.     replaced by spaces.
  1099.  
  1100.  +  Adds a plus sign to a number if its positive, and a minus minus
  1101.     sign if it's negative.
  1102.  
  1103.         PRINT USING "+##";10 : PRINT USING "+##";-10
  1104.  
  1105.  -  Only includes a sign if the number is negative. Positive numbers
  1106.     are preceded by a space.
  1107.  
  1108.  .  Places a decimal point in the number, and centres it neatly on the
  1109.     screen.
  1110.  
  1111.  ;  Centres a number but doesn't output a decimal point.
  1112.  
  1113.  ^  Prints out a number in exponential form.
  1114.  
  1115.         PRINT USING "Here is a number ^";12345.678
  1116.  
  1117.  
  1118.  
  1119.                            REM / ' (comment)
  1120.  
  1121. REM comment
  1122.  
  1123. The REM statements is used to add comments to your Basic program. Any
  1124. text typed in after a REM statement will be completely ignored by AMOS
  1125. Basic.
  1126.  
  1127.         REM This is a comment
  1128.         ' this is a comment.
  1129.  
  1130. So, a quote mark "'" can also be used, but it *must* be placed at the
  1131. absolute beginning of the line.
  1132.  
  1133.  
  1134.  
  1135.                    DATA (place a list of data items                        256
  1136.                        in a AMOS Basic program)
  1137.  
  1138. The DATA statement allows you to incorporate whole lists of useful
  1139. information directly inside a Basic program. This data can be
  1140. subsequently loaded into one or more variables using the READ
  1141. instruction. Each variable in your list is separated by a single comma.
  1142.  
  1143.         DATA 1,2,3,"Hello"
  1144.  
  1145. Unlike most other Basics, the AMOS version of this instruction also
  1146. lets you include expression s as part of your data. So the following
  1147. lines of code are equally acceptable:
  1148.  
  1149.         DATA $FF50,$890
  1150.         DATA %111111111111,%1101010101
  1151.         DATA A
  1152.         Label: Data A+3/2.0-Sin(B)
  1153.         Data "Hello"+"There"
  1154.  
  1155. It's important to realise that the "A" at LABEL will be input as the
  1156. contents of variable A, and not the character A. The expression will be
  1157. evaluated automatically during the READ operation using the lastest
  1158. values of A and B.
  1159.  
  1160.   Also note that each DATA instruction must be the only statement on
  1161. the current line. Anything after this command will be totally ignored!
  1162. Data statements can be placed anywhere in your Basic program. However,
  1163. any data you store inside an AMOS procedure will not be accessible from
  1164. the main program.
  1165.  
  1166.  
  1167.  
  1168.                       READ (read some data a DATA
  1169.                       statement into a variable)
  1170.  
  1171. READ list of variables
  1172.  
  1173. Loads some informatoin stored in a DATA statement into a list of
  1174. variables. READ uses a special marker to determine the location of the
  1175. next piece of data to be entered. At the start of your program, the
  1176. marker is moved to the first item of the first DATA statement. Once
  1177. this item has been read, the marker is advanced so that it points to
  1178. the next item in your list. As you might expect, the variables you read
  1179. must be exactly the same type as the data held at the current position.
  1180. Example:
  1181.  
  1182.         T=10
  1183.         Read A$,B,C,D$
  1184.         Print A$,B,C,D$
  1185.         Data "String",2,T*20+rnd(100),"AMOS "+"Basic"
  1186.  
  1187.  
  1188.  
  1189.                 RESTORE (set the current READ pointer)                     257
  1190.  
  1191. RESTORE Label
  1192. RESTORE LABEL$
  1193. RESTORE Line           RESTORE changes the point at which a subsequent
  1194. RESTORE number         READ operation will expect to find the next DATA
  1195.                        statement. Each AMOS procedure has its own 
  1196. individual data pointer. So any calls to this command wlil only apply
  1197. to the *current* procedure!
  1198.  
  1199.   "label" is a label which specifies the position of the first DATA
  1200. statement to be read. This label name can be calculated as part of an
  1201. expression. The following Basic commands are perfectly legal:
  1202.  
  1203.         RESTORE L
  1204.         RESTORE "L"+"A"+"B"+"E"+"L"
  1205.  
  1206. Similarly, line selects the line number of the next DATA statement.
  1207. Like "label" it can be entered as an expression:
  1208.  
  1209.         RESTORE TEST+2
  1210.  
  1211. By allowing you to jump at will through the DATA statements in your
  1212. program, RESTORE lets you choose your information depending on the
  1213. actions of the user. Each room of an adventure, for instance, could
  1214. have its description stored in a list of simple DATA statements. To
  1215. read this description you could use something like:
  1216.  
  1217.         Restore ROOM*5+1000 : Rem Each ROOM has 5 data statements
  1218.         Read DESC$ : Print DESC$
  1219.             :            :
  1220.  
  1221. Obviously, if a data statement does not exist at the line specified by
  1222. RESTORE, and appropriate error message will be generated. Beware of
  1223. trying to use this command inside a procedure. In order to work, your
  1224. DATA statements *MUST* be within the current procedure.
  1225.  
  1226.  
  1227.  
  1228.                    WAIT (wait in 50ths of a second)                        258
  1229.  
  1230. WAIT n
  1231.  
  1232. Suspends an AMOS Basic program for n/50 of a second. Any functions
  1233. which use interrupts, such as MOVE and MUSIC, will continue to work as
  1234. normal during this period.
  1235.  
  1236.  
  1237.  
  1238.                  =TIMER= (count in 50ths of a second)
  1239.  
  1240. v=TIMER
  1241. TIMER=v
  1242.  
  1243. TIMER is a reserved variable which is incremented by 1 every 50th of a
  1244. second. It's commonly used to set the seed of the random number
  1245. generator like so:
  1246.  
  1247.         Randomize Timer
  1248.  
  1249.  
  1250.  
  1251.                       NOT (logical NOT operation)
  1252.  
  1253. v=NOT(d)
  1254.  
  1255. This function changes every binary digit in a number from a 1 to a 0
  1256. and vice versa. Since True=-1 (%1111111111111) in binary and False=0,
  1257. NOT(True)=False. Example:
  1258.  
  1259.         Print Bin$(Not(%1010),4)
  1260. ( result: 0101 )
  1261.         If Not(True)=False Then Print "False"
  1262.  
  1263.  
  1264.  
  1265.                           TRUE (logical TRUE)
  1266.  
  1267. v=TRUE
  1268.  
  1269. Whenever a test is made such as X>10, a value is produced. If the
  1270. condition is true then this number is set to -1, otherwise it will be
  1271. zero.
  1272.  
  1273.         If -1 Then Print "Minus 1 Is TRUE"
  1274.         If TURE Then Print "and TRUE Is ";TRUE
  1275.  
  1276.  
  1277.                          FALSE (logical FALSE)                             259
  1278.  
  1279. v=FALSE
  1280.  
  1281. Returns a value of zero. This is used by all the conditional operations
  1282. such as IF...THEN and REPEAT...UNTIL to represent FALSE.
  1283.  
  1284.         Print FALSE
  1285. ( result : 0 )
  1286.